/*********************************************************************
*
* Software License Agreement (BSD License)
*
*  Copyright (c) 2010, Heriot-Watt University, UK.
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*   * Neither the name of the Heriot-Watt University nor the names of
*     its contributors may be used to endorse or promote products
*     derived from this software without specific prior written
*     permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
*  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
*  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
*  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
*  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
*  POSSIBILITY OF SUCH DAMAGE.
*
*  Author: Joel Cartwright
*
*********************************************************************/

#ifndef MATCHMAKER_SERVICE_DETAILS_H_
#define MATCHMAKER_SERVICE_DETAILS_H_

#include <iostream>
#include <vector>

#include <ros/ros.h>

#include <matchmaker/service_id.h>
#include <matchmaker/service_status.h>

namespace matchmaker
{

class ServiceDetails;

/**
 * @brief Holds values describing a service discovered by the Client
 */
class ServiceDetails
{
public:
  /**
   * @brief Default constructor
   */
  ServiceDetails();

  /**
   * @brief Constructor, used by the Client class
   * @param name service name
   * @param topic ROS address for the service
   * @param status status of the service
   * @param provider name of the node providing the service
   */
  ServiceDetails(const std::string & name, const std::string & topic,
      ServiceStatus status, const std::string & provider);

  /**
   * @brief Destructor
   */
  virtual ~ServiceDetails();

  /**
   * Test this ServiceDetail instance for full equality with another
   * @param rhs service to compare this against
   * @return
   */
  bool hasSameContent(const ServiceDetails & rhs) const;

  /**
   * Test if this ServiceDetail object has the same provider as another
   * @param rhs service to compare this against
   * @return true if same provider, false otherwise
   */
  bool hasSameProvider(const ServiceDetails & rhs) const;

  /**
   * Test if this ServiceDetail object has the same ID as another
   * @param rhs service to compare this against
   * @return true if same ID, false otherwise
   */
  bool hasSameID(const ServiceDetails & rhs) const;

  /** Unique identifier for this service instance */
  std::string id;

  /** Standard name of the service */
  std::string name;

  /** Specific ROS address for the service */
  std::string topic;

  /** Current status of the service */
  ServiceStatus status;

  /** Name of the provider */
  std::string provider;
};

typedef boost::shared_ptr<ServiceDetails> ServiceDetailsPtr;
typedef boost::shared_ptr<const ServiceDetails> ServiceDetailsConstPtr;

typedef std::list<ServiceDetailsPtr> L_ServiceDetails;
typedef boost::shared_ptr<L_ServiceDetails> L_ServiceDetailsPtr;

typedef std::map<std::string, ServiceDetails> M_NameToServiceDetails;
typedef boost::shared_ptr<M_NameToServiceDetails> M_NameToServiceDetailsPtr;

} // namespace

#endif /* MATCHMAKER_SERVICE_DETAILS_H_ */
